package com.example.alpha.campusbase.Fragment;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.alpha.campusbase.Activity.LoginActivity;
import com.example.alpha.campusbase.Activity.MainActivity;
import com.example.alpha.campusbase.R;
import com.example.alpha.campusbase.UserLocalStore;

/**
 * Created by Alpha on 2016/6/2.
 */

public class MineFragment extends Fragment implements View.OnClickListener{

    private Context mAContent;
    private Context mContent;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAContent=getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View mMineView=inflater.inflate(R.layout.mine_layout,container,false);
        mContent=getContext();

        TextView mDetailView= (TextView) mMineView.findViewById(R.id.mine_account_detail);
        TextView mSettingView= (TextView) mMineView.findViewById(R.id.mine_account_setting);
        TextView mWelcomeView= (TextView) mMineView.findViewById(R.id.mine_account_welcome);
        TextView mLogoutView= (TextView) mMineView.findViewById(R.id.mine_account_logout);
        mDetailView.setOnClickListener(this);
        mSettingView.setOnClickListener(this);
        mWelcomeView.setOnClickListener(this);
        mLogoutView.setOnClickListener(this);

        return  mMineView;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.mine_account_detail:
                break;
            case R.id.mine_account_logout:
                //工厂设计模式
                AlertDialog.Builder builder=new AlertDialog.Builder(mAContent);
                builder.setTitle(getResources().getString(R.string.exit_login));
                builder.setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        UserLocalStore mULS=new UserLocalStore(mAContent);
                        mULS.setUserLoggenIn(false);
                        //mULS.clearUserData();
                        Intent intent=new Intent(mAContent, LoginActivity.class);
                        startActivity(intent);
                        getActivity().finish();
                    }
                });
                builder.setNegativeButton(getResources().getString(R.string.cancle), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();
                break;
        }

    }
}
